import { bodyConfigs, createBodyGetter } from "@/role/bodyUtils"
import { CreepConfig, CreepRole, RoleCreep, RoleDatas } from "@/role/types/role"
import { getBodySpawnEnergy } from "@/utils"



export const harvester: CreepConfig<CreepRole.Harvester> = {
    target: (creep: RoleCreep) => {
        return true
    },
    bodys: (room: Room, spawn: StructureSpawn, data: RoleDatas[CreepRole.Harvester]) => {
        const source = Game.getObjectById(data.sourceId)

        // 如果没视野或者边上没有 Link 的话，就用 harvester 标准的部件
        const bodyConfig = !source || !source.getLink()
            ? bodyConfigs.harvester
            : bodyConfigs.worker

        const bodyPartGenerator = createBodyGetter(bodyConfig)(room, spawn)
        console.log(room.name, 'harvester bodyPartGenerator', bodyPartGenerator, getBodySpawnEnergy(bodyPartGenerator))
        return bodyPartGenerator
    }
}


export const manager: CreepConfig<CreepRole.Manager> = {
    target: (creep: RoleCreep) => {
        return true
    },
    bodys: (room: Room, spawn: StructureSpawn, data: RoleDatas[CreepRole.Manager]) => {
        const bodyConfig = bodyConfigs.manager
        let bodyPartGenerator
        // if (data.bodyType) {
        //     // 指定了特殊身体部件的话就生成对应的
        //     bodyPartGenerator = specialBodyConfig[data.bodyType](room, spawn)
        // }
        // else {
        // 否则就使用默认的身体部件
        bodyPartGenerator = createBodyGetter(bodyConfig)(room, spawn)
        // }
        console.log(room.name, 'manager bodyPartGenerator', bodyPartGenerator, getBodySpawnEnergy(bodyPartGenerator))
        return bodyPartGenerator
    }
}


export const worker: CreepConfig<CreepRole.Worker> = {
    target: (creep: RoleCreep) => {
        return true
    },
    bodys: (room: Room, spawn: StructureSpawn, data: RoleDatas[CreepRole.Worker]) => {
        const bodyConfig = bodyConfigs.worker
        let bodyPartGenerator
        // if (data.bodyType) {
        //     // 指定了特殊身体部件的话就生成对应的
        //     bodyPartGenerator = specialBodyConfig[data.bodyType](room, spawn)
        // }
        // else {
        // 否则就使用默认的身体部件
        bodyPartGenerator = createBodyGetter(bodyConfig)(room, spawn)
        // }
        console.log(room.name, 'worker bodyPartGenerator', bodyPartGenerator, getBodySpawnEnergy(bodyPartGenerator))
        return bodyPartGenerator
    }
}
